﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Campus.Main.Basic.InsertValues;
using cpmntctrl;
using dbcntn;

namespace Campus.Main.Basic.Settings
{
    public partial class HazirlikBall : DefaultForm
    {
        public HazirlikBall(string text)
        {
            InitializeComponent();
            aToDb=new ConnectionToDb(Helper.ConnectionString);
            aToDb.AddItemDBGridView(dataGridView1,Query.Hazirlik);
            ControlComponent.UnVisibleCells(dataGridView1,0);
            student_id = text;
            
        }

        public int HazirlikBallId { get; private set; }
        public int Ball { get; private set; }
        private string student_id;
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            var data = new List<string>();
            ControlComponent.AddToList(data, dataGridView1, e, 0, 1,2);
            Hazirlik f = new Hazirlik(data);
            f.FormClosed += Bind;
            f.ShowDialog();
        }

        public override void Bind(object sender, FormClosedEventArgs e)
        {
            Initialize();
            aToDb.AddItemDBGridView(dataGridView1, Query.Hazirlik);
            ControlComponent.UnVisibleCells(dataGridView1, 0);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (HazirlikBallId != 0)
            {
                Close();
                aToDb.UpdateMainTable("hazirlikball_id",HazirlikBallId,student_id);
            }
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            HazirlikBallId = Convert.ToInt32(dataGridView1[0, e.RowIndex].Value);
            Ball = Convert.ToInt32(dataGridView1[2, e.RowIndex].Value);
        }

        private void HazirlikBall_Load(object sender, EventArgs e)
        {
            HazirlikBallId =
                Int32.Parse(aToDb.SelectField("select hazirlikball_id from onmaintable where student_id like('" + student_id + "')"));
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (Convert.ToInt32(dataGridView1[0, i].Value) == HazirlikBallId)
                {
                    dataGridView1.Rows[i].Selected = true;
                    dataGridView1.CurrentCell=dataGridView1[1,i];
                    break;
                }
            }
        }
    }
}
